﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class DingDanStatus:Repository,IBll.IDingDanStatus
    {
        private IDao.IDingDanStatusDAO dingDanStatusDAO = new Dao.DingDanStatusDAO();
        public Model.Common.JsonResult Add(DTO.DingDanStatusDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_DingDanStatus model_DingDanStatus = new Model.Entities.Model_DingDanStatus();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_DingDanStatus);
            if (string.IsNullOrEmpty(model_DingDanStatus.ID) || model_DingDanStatus.ID.Trim() == "")
            {
                model_DingDanStatus.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = dingDanStatusDAO.Add(model_DingDanStatus);
            return jsonResult;
        }

        public Model.Common.JsonResult Delete(DTO.DingDanStatusDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_DingDanStatus model_DingDanStatus = new Model.Entities.Model_DingDanStatus();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_DingDanStatus);
            jsonResult.Success = dingDanStatusDAO.Delete(model_DingDanStatus);
            return jsonResult;
        }

        public Model.Common.JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = dingDanStatusDAO.Delete(id);
            return jsonResult;
        }

        public Model.Common.JsonResult Update(DTO.DingDanStatusDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_DingDanStatus model_DingDanStatus = new Model.Entities.Model_DingDanStatus();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_DingDanStatus);
            jsonResult.Success = dingDanStatusDAO.Update(model_DingDanStatus);
            return jsonResult;
        }

        public DTO.DingDanStatusDTO GetByID(string id)
        {
            Model.Entities.Model_DingDanStatus model_DingDanStatus = dingDanStatusDAO.GetByID(id);
            DTO.DingDanStatusDTO dingDanStatusDTO = new DTO.DingDanStatusDTO();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(model_DingDanStatus, dingDanStatusDTO);
            return dingDanStatusDTO;
        }

        public List<DTO.DingDanStatusDTO> GetAllDingDanStatus()
        {
            List<Model.Entities.Model_DingDanStatus> model_ListDingDanStatus = dingDanStatusDAO.GetAllDingDanStatus();
            List<DTO.DingDanStatusDTO> dto_ListDingDanStatus = new List<DTO.DingDanStatusDTO>();
            foreach (var item in model_ListDingDanStatus)
            {
                DTO.DingDanStatusDTO dingDanStatusDTO = new DTO.DingDanStatusDTO();
                Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(item, dingDanStatusDTO);
                dto_ListDingDanStatus.Add(dingDanStatusDTO);
            }
            return dto_ListDingDanStatus;
        }
    }
}
